import server from '@/utils/http';
import { PaginationQuery } from '@/types/table';
import { DeptsQuery } from '@/types/depts';

enum Api {
    jobs = '/api/job',
    dept = '/api/dept',
    deptTree = '/api/dept/tree',
    role = '/api/roles',
    menu = '/api/menus',
    dict = '/api/dict',
    dictDetail = '/api/dictDetail',
    dictDetailMap = '/api/dictDetail/map',
    rolesMenu = '/api/roles/menu',
    menusbuild = '/api/menus/assign',
    menusbuild1 = '/api/menus/build',
    skuDict = '/api/skuDict',
    skuDictMerchant = '/api/skuDict/merchant',
}

/**
 * @description 获取岗位列表
 * @param page 页码
 * @param size pageSize
 * @sort 排序方式 默认level,asc
 * @return { content: 列表, totalElements： 总数 }
 */
export const getJobs = (query: PaginationQuery): Promise<TableResponse> => {
    return server.Get(Api.jobs, query);
};

/**
 * @description 获取部门列表
 * @param pid 父节点id
 * @param sort 排序方式
 * @return { content: 列表, totalElements： 总数 }
 * 实际上好像不需要这些分页的参数，接口文档不对
 */
export const getDepts = (params?: DeptsQuery | PaginationQuery): Promise<TableResponse> => {
    return server.Get(Api.dept, params);
};
/**
 * @description 获取部门列表
 * @param pid 父节点id
 * @param sort 排序方式
 * @return { content: 列表, totalElements： 总数 }
 * 实际上好像不需要这些分页的参数，接口文档不对
 */
export const getDeptsTree = (params?: DeptsQuery | PaginationQuery): Promise<TableResponse> => {
    return server.Get(Api.deptTree, params);
};
/**
 *
 * @description 新增部门
 * @param dept info
 */
export const addDept = (params: NormalObj): Promise<void> => {
    return server.Post(Api.dept, params);
};
/**
 *
 * @description 编辑部门
 * @param dept info
 */
export const editDept = (params: NormalObj): Promise<void> => {
    return server.Put(Api.dept, params);
};
/**
 * @description 删除部门
 * @param ids 角色id
 */
export const deleteDepts = (params: (string | number)[]): Promise<void> => {
    return server.Delete(Api.dept, { data: params });
};

/**
 * @description 获取角色列表
 * @param page 页码
 * @param size pageSize
 * @sort 排序方式 默认level,asc
 * @return { content: 列表, totalElements: 总数 }
 */
export const getRoles = (query: PaginationQuery): Promise<TableResponse> => {
    return server.Get(Api.role, query);
};

/**
 * @description 添加角色
 * @param ids 角色id
 */
export const addRoles = (params: NormalObj): Promise<void> => {
    return server.Post(Api.role, params);
};
/**
 * @description 编辑角色
 * @param ids 角色id
 */
export const editRoles = (params: NormalObj): Promise<void> => {
    return server.Put(Api.role, params);
};
/**
 * @description 删除角色
 * @param ids 角色id
 */
export const deleteRoles = (params: (string | number)[]): Promise<void> => {
    return server.Delete(Api.role, { data: params });
};

/**
 * @description 获取菜单列表
 */
export const getmenusbuild = (query: { needId: boolean }): Promise<any[]> => {
    return server.Get(Api.menusbuild, query);
};

/**
 * @description 获取菜单列表
 */
export const getmenusbuild1 = (): Promise<any[]> => {
    return server.Get(Api.menusbuild1);
};
/**
 * @description 获取全部菜单列表
 */
export const getMenus = (query: PaginationQuery | DeptsQuery): Promise<TableResponse> => {
    return server.Get(Api.menu, query);
};

/**
 *
 * @description 添加菜单
 * @param menu info
 */
export const addMenu = (params: NormalObj): Promise<void> => {
    return server.Post(Api.menu, params);
};
/**
 *
 * @description 编辑菜单
 * @param menu info
 */
export const editMenu = (params: NormalObj): Promise<void> => {
    return server.Put(Api.menu, params);
};
/**
 * @description 删除菜单
 * @param ids 角色id
 */
export const deleteMenus = (params: (string | number)[]): Promise<void> => {
    return server.Delete(Api.menu, { data: params });
};

/**
 * @description 获取字典列表
 */
export const getDicts = (query: PaginationQuery | DeptsQuery): Promise<TableResponse> => {
    return server.Get(Api.dict, query);
};
/**
 * @description 添加字典
 * @param dict info
 */
export const addDict = (params: NormalObj): Promise<void> => {
    return server.Post(Api.dict, params);
};
/**
 * @description 编辑字典
 * @param ids 角色id
 */
export const editDict = (params: NormalObj): Promise<void> => {
    return server.Put(Api.dict, params);
};
/**
 * @description 删除字典
 * @param ids 角色id
 */
export const deleteDicts = (params: (string | number)[]): Promise<void> => {
    return server.Delete(Api.dict, { data: params });
};
/**
 * @description 查询商品字典
 */
export const getskuDict = (): Promise<any[]> => {
    return server.Get(Api.skuDict);
};
/**
 * @description 查询商品字典
 */
export const getskuDictMerchant = (): Promise<any[]> => {
    return server.Get(Api.skuDictMerchant);
};

/**
 * @description 获取字典详情列表
 */
export const getDictDetails = (query: PaginationQuery | DeptsQuery): Promise<TableResponse> => {
    return server.Get(Api.dictDetail, query);
};
/**
 * @description 获取多个字典详情列表
 */
export const getDictDetailMaps = (query: PaginationQuery | DeptsQuery): Promise<TableResponse> => {
    return server.Get(Api.dictDetailMap, query);
};
/**
 * @description 添加字典详情
 * @param dictDetail info
 */
export const addDictDetail = (params: NormalObj): Promise<void> => {
    return server.Post(Api.dictDetail, params);
};
/**
 * @description 编辑字典详情
 * @param dictDetail info
 */
export const editDictDetail = (params: NormalObj): Promise<void> => {
    return server.Put(Api.dictDetail, params);
};
/**
 * @description 删除字典详情
 * @param ids 角色id
 */
export const deleteDictDetail = (params: number): Promise<void> => {
    return server.Delete(`${Api.dictDetail}/${params}`);
};

/**
 *
 * @description 编辑角色权限
 * @param menu info
 */
export const editRolsMenu = (params: NormalObj): Promise<void> => {
    return server.Put(Api.rolesMenu, params);
};

/**
 * @description 数据导出
 * @param
 */
export const getDownload = (Api: string, name: string) => {
    server.Download(Api, { data: '' }, { responseType: 'blob' }, name);
};
